<!DOCTYPE html>
<html lang="zh-CN">
<head>
    {% load static %}
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}CDN预热平台{% endblock %}</title>
    <!-- 引入 Bootstrap CSS -->
    <link rel="stylesheet" href="{% static 'preheat/css/bootstrap.min.css' %}">
    <!-- 使用本地jQuery文件以避免依赖外部CDN -->
    <script src="{% static 'preheat/js/jquery.min.js' %}"></script>
    <!-- 引入 Bootstrap JS -->
    <script src="{% static 'preheat/js/bootstrap.bundle.min.js' %}"></script>
    
    <!-- 引入 Font Awesome 图标库 -->
    <link rel="stylesheet" href="{% static 'preheat/font-awesome/css/all.min.css' %}">
    
    <!-- 引入优化样式表 -->
    <link rel="stylesheet" href="{% static 'preheat/css/optimized_styles.css' %}">
    
    <!-- 自定义 CSS -->
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
        }
        
        /* 侧边栏样式 - 与Bootstrap栅格系统协同工作 */
        .sidebar {
            background-color: #2c3e50;
            color: white;
            height: 100vh;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1030;
            overflow-x: hidden;
            overflow-y: auto;
            box-shadow: 1px 0 5px rgba(0, 0, 0, 0.1);
            width: 250px; /* 默认宽度 - 大屏幕 */
            padding-top: 20px;
        }
        
        .sidebar h4 {
            color: #fff;
            font-weight: 600;
            margin-bottom: 20px;
            padding: 0 15px 15px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .sidebar a {
            color: rgba(255, 255, 255, 0.9);
            display: flex;
            align-items: center;
            padding: 10px 15px;
            text-decoration: none;
            margin: 0;
        }
        
        .sidebar a:hover {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }
        
        .sidebar a.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white;
            font-weight: 600;
            border-left: 3px solid #3498db;
        }
        
        .sidebar a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        
        .sidebar .border-t {
            border-color: rgba(255, 255, 255, 0.1) !important;
        }
        
        .logout-button {
            width: 100%;
            text-align: left;
            color: rgba(255, 255, 255, 0.9);
            padding: 10px 15px;
            font-weight: normal;
            background: transparent;
            border: none;
            display: flex;
            align-items: center;
        }
        
        .logout-button:hover {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }
        
        .logout-button i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        
        /* 主内容区样式 - 与Bootstrap栅格系统协同工作 */
        .main-content {
            min-height: 100vh;
            padding: 20px;
            background-color: #f8f9fa;
        }
        
        .main-content h1, .main-content h2, .main-content h3, .main-content h4, .main-content h5, .main-content h6 {
            color: #2c3e50;
            font-weight: 600;
            margin-bottom: 1rem;
        }
        
        .main-content .card {
            border: 1px solid #dee2e6;
            border-radius: 4px;
            box-shadow: none;
            margin-bottom: 1.5rem;
        }
        
        .main-content .card-header {
            background-color: #f8f9fa;
            color: #2c3e50;
            border-bottom: 1px solid #dee2e6;
            font-weight: 600;
            padding: 12px 20px;
        }
        
        .main-content .btn {
            border-radius: 4px;
            padding: 6px 12px;
            font-weight: 500;
        }
        
        .main-content .btn-primary {
            background-color: #007bff;
            border-color: #007bff;
        }
        
        .main-content .btn-primary:hover {
            background-color: #0069d9;
            border-color: #0062cc;
        }
        
        .main-content .table {
            border: 1px solid #dee2e6;
        }
        
        .main-content .table thead th {
            background-color: #f8f9fa;
            color: #2c3e50;
            border-bottom: 2px solid #dee2e6;
            font-weight: 600;
        }
        
        .main-content .badge {
            padding: 4px 8px;
            border-radius: 4px;
            font-weight: 500;
            background-color: #007bff;
            color: white;
        }
        
        /* 大屏幕上覆盖Bootstrap栅格系统，使用固定宽度布局 */
        @media (min-width: 992px) {
            .main-content {
                margin-left: 250px; /* 与侧边栏宽度匹配 */
                width: calc(100% - 250px); /* 计算剩余宽度 */
            }
        }
        

        
        /* 表单样式 */
        .main-content .form-control {
            border-radius: 4px;
            border: 1px solid #ced4da;
            padding: 8px 12px;
        }
        
        .main-content .form-control:focus {
            border-color: #80bdff;
            box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
        }
        
        .main-content .form-label {
            font-weight: 500;
            color: #2c3e50;
            margin-bottom: 0.5rem;
        }
        
        .main-content .form-select {
            border-radius: 4px;
            border: 1px solid #ced4da;
            padding: 8px 12px;
        }
        
        .main-content .form-select:focus {
            border-color: #80bdff;
            box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
        }
        
        .main-content .form-check-input:checked {
            background-color: #007bff;
            border-color: #007bff;
        }
        
        .main-content .form-check-input:focus {
            border-color: #80bdff;
            box-shadow: 0 0 0 0.25rem rgba(0, 123, 255, 0.25);
        }
        
        .main-content .form-switch .form-check-input:checked {
            background-color: #007bff;
            border-color: #007bff;
        }
        
        /* 响应式布局 - 简化版，仅处理关键断点 */
        
        /* 小屏幕和移动设备 */
        @media (max-width: 991px) {
            .sidebar {
                width: 100%;
                position: relative;
                height: auto;
                padding-top: 10px;
                margin-bottom: 20px;
            }
            
            .main-content {
                margin-left: 0 !important;
                width: 100% !important;
            }
            
            .container {
                padding: 0 15px;
            }
        }
        
        /* 大屏幕专用优化 */
        @media (min-width: 1200px) {
            /* 优化宽屏下内容显示 */
            .container {
                max-width: 100%;
            }
            
            /* 卡片间距优化 */
            .card {
                margin-bottom: 30px;
            }
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-2 sidebar">
                <h4 class="text-center mb-4">CDN预热平台</h4>
                <ul class="list-unstyled">
                    <li><a href="{% url 'preheat:home' %}" class="{% if request.resolver_match.url_name == 'home' %}active{% endif %}"><i class="fas fa-home"></i> 首页</a></li>
                    <li><a href="{% url 'preheat:server_list' %}" class="{% if request.resolver_match.url_name == 'server_list' or request.resolver_match.url_name == 'server_create' or request.resolver_match.url_name == 'server_delete' %}active{% endif %}"><i class="fas fa-server"></i> 服务器管理</a></li>
                    <li><a href="{% url 'preheat:cdn_domain_list' %}" class="{% if request.resolver_match.url_name == 'cdn_domain_list' or request.resolver_match.url_name == 'cdn_domain_create' or request.resolver_match.url_name == 'cdn_domain_delete' %}active{% endif %}"><i class="fas fa-globe"></i> CDN域名管理</a></li>
                    <li><a href="{% url 'preheat:request_url_list' %}" class="{% if request.resolver_match.url_name == 'request_url_list' or request.resolver_match.url_name == 'request_url_create' or request.resolver_match.url_name == 'request_url_delete' %}active{% endif %}"><i class="fas fa-link"></i> 请求地址管理</a></li>
                    <li><a href="{% url 'preheat:auto_task_list' %}" class="{% if request.resolver_match.url_name == 'auto_task_list' or request.resolver_match.url_name == 'auto_task_create' or request.resolver_match.url_name == 'auto_task_delete' or request.resolver_match.url_name == 'auto_task_detail' %}active{% endif %}"><i class="fas fa-tasks"></i> 自动任务管理</a></li>
                    <li><a href="{% url 'preheat:manual_preheat_create' %}" class="{% if request.resolver_match.url_name == 'manual_preheat_create' or request.resolver_match.url_name == 'manual_preheat_status' %}active{% endif %}"><i class="fas fa-fire"></i> 立即预热</a></li>
                    {% if user.is_authenticated %}
                    <li><a href="{% url 'preheat:user_list' %}" class="{% if request.resolver_match.url_name == 'user_list' or request.resolver_match.url_name == 'user_create' or request.resolver_match.url_name == 'user_update' or request.resolver_match.url_name == 'user_delete' %}active{% endif %}"><i class="fas fa-users"></i> 用户管理</a></li>
                    <li class="mt-4 pt-4 border-t border-gray-700">
                        <a href="/admin/"><i class="fas fa-cog"></i> 管理后台</a>
                    </li>
                    <li class="mt-2">
                        <a href="{% url 'preheat:user_password_change' user.pk %}"><i class="fas fa-key"></i> 修改密码</a>
                    </li>
                    <li class="mt-2">
                        <form method="post" action="{% url 'preheat:logout' %}" style="display: inline;">
                            {% csrf_token %}
                            <button type="submit" class="logout-button"><i class="fas fa-sign-out-alt"></i> 退出登录 ({{ user.username }})</button>
                        </form>
                    </li>
                    {% else %}
                    <li class="mt-4 pt-4 border-t border-gray-700">
                        <a href="{% url 'preheat:login' %}"><i class="fas fa-sign-in-alt"></i> 登录</a>
                    </li>
                    {% endif %}
                </ul>
            </div>
            
            <!-- 主内容区域 -->
            <div class="col-md-10 main-content">
                <!-- 页面标题 -->
                <div class="card">
                    <div class="card-header">
                        <h1 class="h3">{% block page_title %}{% endblock %}</h1>
                    </div>
                    <div class="card-body">
                        <!-- 消息提示 -->
                        {% if messages %}
                            {% for message in messages %}
                                <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                                    {{ message }}
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                            {% endfor %}
                        {% endif %}
                        
                        <!-- 页面内容 -->
                        {% block content %}{% endblock %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    {% block extra_js %}{% endblock %}
</body>
</html>